<?php
namespace App\Models;

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
class EncryptField
{
    private string $encKey;
    public function __construct($key)
    {
        $this->encKey=$key;
        var_dump($key);
        throw new \Exception('Not implemented');
    }
    // 加密函数
    public function encrypt($str) {
    $data = openssl_encrypt($str, 'AES-128-ECB', $this->encKey, OPENSSL_RAW_DATA);
    return base64_encode($data);
    }

    // 解密函数
    public function decrypt($str) {
    $decrypted = openssl_decrypt(base64_decode($str), 'AES-128-ECB', $this->encKey, OPENSSL_RAW_DATA);
    return $decrypted;
    }
}
